﻿@model List<RoadQualityEvalAPI.Models.UserModel>

@{
	var totalUsersCount = Model.Count;
}



<script type="text/javascript">


	$('.userCreate').on('click', function (evt) {


		evt.preventDefault();
		evt.stopPropagation();

		//alert("Clicked");
		console.log('clicked');

		var $contentDiv = $('#content'), url = $(this).data('url');

		$.get(url, function (data) {

			$contentDiv.replaceWith(data);

		});

	});


	$('.userEdit').on('click', function (evt) {


		evt.preventDefault();
		evt.stopPropagation();

		//alert("Clicked");
		console.log('clicked');

		var $contentDiv = $('#content'), url = $(this).data('url');

		$.get(url, function (data) {

			$contentDiv.replaceWith(data);

		});

	});

</script>



<h4>User Administration:</h4>
<hr />
<div id="users_administration">

	<div class="row">
		<p>Users account administration section</p>
		<p>Manage the registered users in the system (create new users, remove, update existing users, etc.)</p>
	</div>


	<div class="row">
		@Html.Label("Total number of users: " + totalUsersCount)
	</div>

	<div class="row">
		@*
		@Html.ActionLink("Create New User", "CreateUser", new { area = "" }, new { @class = "userCreate" })
		*@
		<button data-url='@Url.Action("CreateUser", "Admin")' class="userCreate">Create New User</button>
		
	</div>

	<div class="row">

		<table class="customTable">
			<tr>
				<th>
					@Html.DisplayNameFor(m => m.FirstOrDefault().CreatedAt)
				</th>
				<th>
					@Html.DisplayNameFor(m => m.FirstOrDefault().UserName)
				</th>
				<th>
					@Html.DisplayNameFor(m => m.FirstOrDefault().UserInfo)
				</th>
				<th>
					@Html.DisplayNameFor(m => m.FirstOrDefault().Email)
				</th>
				<th>
					@Html.Raw("Actions")
				</th>
			</tr>

			@foreach (var user in Model)
			{
				<tr>
					<td>
						@Html.DisplayFor(m => user.CreatedAt)
					</td>
					<td>
						@Html.DisplayFor(m => user.UserName)
					</td>
					<td>
						@Html.DisplayFor(m => user.UserInfo)
					</td>
					<td>
						@Html.DisplayFor(m => user.Email)
					</td>
					<td>
						<button data-url='@Url.Action("EditUser", "Admin", new { id = user.UserId })' class="userEdit">Edit User</button>
						@Html.ActionLink("See User Details", "UserDetails", new { }) |
						@Html.ActionLink("Delete User", "DeleteUser", new { id = user.UserId }, new { onclick = "return confirm('Are you sure you wish to delete this user?');" })
					</td>
				</tr>
			}
		</table>

	</div>

</div>
